package com.qys.livesMall.event.listener;

import cn.hutool.core.bean.BeanUtil;
import com.qys.livesMall.anchor.event.pojo.UserGradeIntegralPOJO;
import com.qys.livesMall.anchor.service.UserGradeIntegralService;
import com.qys.livesMall.shop.event.UserGradeIntegralOrderEvent;
import com.qys.livesMall.shop.event.pojo.UserGradeIntegralOrderPOJO;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

@RequiredArgsConstructor
public class UserGradeIntegralOrderListener {

    private final UserGradeIntegralService userGradeIntegralService;

    @Async
    @Order
    @EventListener(UserGradeIntegralOrderEvent.class)
    public void addUserGradeIntegral(UserGradeIntegralOrderEvent event){
        UserGradeIntegralOrderPOJO  pojo= (UserGradeIntegralOrderPOJO) event.getSource();
        UserGradeIntegralPOJO userGradeIntegralPOJO=new UserGradeIntegralPOJO();
        BeanUtil.copyProperties(pojo,userGradeIntegralPOJO);
        userGradeIntegralService.addUserGradeIntegral(userGradeIntegralPOJO);
    }
}
